package com.xyht.sca_s.student_manage_system.modules.rxRegistration.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ExceptionCast;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.modules.payment.wxpay.util.WxPayUtil;
import com.xyht.sca_s.student_manage_system.modules.rxRegistration.entity.*;
import com.xyht.sca_s.student_manage_system.modules.rxRegistration.entity.req.RxRegistrationChargeCategoryReq;
import com.xyht.sca_s.student_manage_system.modules.rxRegistration.entity.req.RxRegistrationCustomColumnReq;
import com.xyht.sca_s.student_manage_system.modules.rxRegistration.entity.req.RxRegistrationPlanDetailSettingReq;
import com.xyht.sca_s.student_manage_system.modules.rxRegistration.entity.req.RxRegistrationPlanSettingReq;
import com.xyht.sca_s.student_manage_system.modules.rxRegistration.entity.resp.*;
import com.xyht.sca_s.student_manage_system.modules.rxRegistration.mapper.*;
import com.xyht.sca_s.student_manage_system.modules.rxRegistration.service.RxRegistrationPlanSettingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationAdvance.entity.RxRegistrationAdvanceStudentInfo;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationAdvance.mapper.RxRegistrationAdvanceStudentInfoMapper;
import com.xyht.sca_s.student_manage_system.modules.user.entity.SmsUser;
import com.xyht.sca_s.student_manage_system.modules.user.entity.resp.SmsSearchUserResp;
import com.xyht.sca_s.student_manage_system.modules.user.mapper.SmsUserMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.xyht.sca_s.student_manage_system.common.util.ParamCheckUtil.isNullOrEmpty;
import static com.xyht.sca_s.student_manage_system.modules.rxRegistration.constant.AppTypeConstant.*;
import static com.xyht.sca_s.student_manage_system.modules.rxRegistration.constant.ChargeCategoryTypeConstant.*;
import static com.xyht.sca_s.student_manage_system.modules.rxRegistration.constant.PlanStatusConstant.PLAN_STATUS_ENABLE;
import static com.xyht.sca_s.student_manage_system.modules.rxRegistration.constant.PlanStatusConstant.PLAN_STATUS_NOT_ENABLE;

/**
 * <p>
 * 招生计划设置 服务实现类
 * </p>
 *
 * @author XYHT
 * @since 2024-05-07
 */
@Service
public class RxRegistrationPlanSettingServiceImpl extends ServiceImpl<RxRegistrationPlanSettingMapper, RxRegistrationPlanSetting> implements RxRegistrationPlanSettingService {
    @Resource
    private RxRegistrationPlanSettingMapper rxRegistrationPlanSettingMapper;
    @Resource
    private RxRegistrationPlanChargeCategorySettingMapper rxRegistrationPlanChargeCategorySettingMapper;
    @Resource
    private RxRegistrationPlanAppSettingMapper rxRegistrationPlanAppSettingMapper;
    @Resource
    private RxRegistrationCustomColumnMapper rxRegistrationCustomColumnMapper;
    @Resource
    private RxRegistrationChargeCategoryMapper rxRegistrationChargeCategoryMapper;
    @Resource
    private RxRegistrationChargeCategoryDetailMapper rxRegistrationChargeCategoryDetailMapper;
    @Resource
    private SmsUserMapper smsUserMapper;
    @Resource
    private WxPayUtil wxPayUtil;
    @Resource
    private RxRegistrationAdvanceStudentInfoMapper rxRegistrationAdvanceStudentInfoMapper;

    @Override
    @Transactional
    public ResponseResult addRxRegistrationPlanSetting(RxRegistrationPlanSettingReq settingReq, String user_id) {
        if (isNullOrEmpty(settingReq.getPlanName(), settingReq.getPlanStatus(), settingReq.getPlanChargeShopSort())) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }

        if (settingReq.getPlanStatus() != PLAN_STATUS_NOT_ENABLE && settingReq.getPlanStatus() != PLAN_STATUS_ENABLE) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }

        //校验商户设置
        List<Map<String, Object>> shopList = wxPayUtil.getPayStoreList();
        if (settingReq.getPlanChargeShopSort() > shopList.size() || settingReq.getPlanChargeShopSort() == 0) {
            return CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_CHARGE_SHOP_NOT_EXIST);
        }
        Map<String, Object> shopMap = shopList.get(settingReq.getPlanChargeShopSort() - 1);

        //开启新招生计划，需要先关闭其余计划
        if (settingReq.getPlanStatus() == PLAN_STATUS_ENABLE) {
            List<RxRegistrationPlanSetting> list = rxRegistrationPlanSettingMapper.selectList(new LambdaQueryWrapper<RxRegistrationPlanSetting>()
                    .eq(RxRegistrationPlanSetting::getPlanStatus, PLAN_STATUS_ENABLE));
            if (list != null && list.size() > 0) {
                for (RxRegistrationPlanSetting setting : list) {
                    setting.setPlanStatus(PLAN_STATUS_NOT_ENABLE);
                    rxRegistrationPlanSettingMapper.updateById(setting);
                }
            }
        }

        RxRegistrationPlanSetting addSetting = new RxRegistrationPlanSetting();
        addSetting.setPlanName(settingReq.getPlanName());
        addSetting.setPlanStatus(settingReq.getPlanStatus());
        addSetting.setPlanChargeShopSort(settingReq.getPlanChargeShopSort());
        addSetting.setPlanChargeShopName((String) shopMap.get("name"));
        rxRegistrationPlanSettingMapper.insert(addSetting);
        return CommonResult.success();
    }

    @Override
    @Transactional
    public ResponseResult updateRxRegistrationPlanSetting(RxRegistrationPlanSettingReq settingReq) {
        if (isNullOrEmpty(settingReq.getId())) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }
        RxRegistrationPlanSetting updateSetting = new RxRegistrationPlanSetting();

        if (!isNullOrEmpty(settingReq.getPlanChargeShopSort())) {
            //校验商户设置
            List<Map<String, Object>> shopList = wxPayUtil.getPayStoreList();
            if (settingReq.getPlanChargeShopSort() > shopList.size() || settingReq.getPlanChargeShopSort() == 0) {
                return CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_CHARGE_SHOP_NOT_EXIST);
            }
            Map<String, Object> shopMap = shopList.get(settingReq.getPlanChargeShopSort() - 1);
            updateSetting.setPlanChargeShopSort(settingReq.getPlanChargeShopSort());
            updateSetting.setPlanChargeShopName((String) shopMap.get("name"));
        }

        if (!isNullOrEmpty(settingReq.getPlanStatus())) {
            if (settingReq.getPlanStatus() != PLAN_STATUS_NOT_ENABLE
                    && settingReq.getPlanStatus() != PLAN_STATUS_ENABLE) {
                return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
            }

            //开启新招生计划，需要先关闭其余计划
            if (settingReq.getPlanStatus() == PLAN_STATUS_ENABLE) {
                List<RxRegistrationPlanSetting> list = rxRegistrationPlanSettingMapper.selectList(new LambdaQueryWrapper<RxRegistrationPlanSetting>()
                        .eq(RxRegistrationPlanSetting::getPlanStatus, PLAN_STATUS_ENABLE));
                if (list != null && list.size() > 0) {
                    for (RxRegistrationPlanSetting setting : list) {
                        setting.setPlanStatus(PLAN_STATUS_NOT_ENABLE);
                        rxRegistrationPlanSettingMapper.updateById(setting);
                    }
                }
            }
        }

        updateSetting.setPlanName(isNullOrEmpty(settingReq.getPlanName()) ? null : settingReq.getPlanName());
        updateSetting.setPlanStatus(isNullOrEmpty(settingReq.getPlanStatus()) ? null : settingReq.getPlanStatus());
        updateSetting.setId(settingReq.getId());
        rxRegistrationPlanSettingMapper.updateById(updateSetting);
        return CommonResult.success();
    }

    @Override
    public ResponseResult deleteRxRegistrationPlanSetting(RxRegistrationPlanSettingReq settingReq) {
        if (isNullOrEmpty(settingReq.getId())) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }

        rxRegistrationPlanSettingMapper.deleteById(settingReq.getId());
        return CommonResult.success();
    }

    @Override
    public ResponseResult getRxRegistrationPlanSettingList(String searchStr, Integer status, Integer pageNum, Integer pageSize) {
        LambdaQueryWrapper<RxRegistrationPlanSetting> queryWrapper = new LambdaQueryWrapper<>();
        if (!isNullOrEmpty(searchStr)) {
            queryWrapper.like(RxRegistrationPlanSetting::getPlanName, searchStr);
        }
        if (!isNullOrEmpty(status)) {
            queryWrapper.eq(RxRegistrationPlanSetting::getPlanStatus, status);
        }

        queryWrapper.orderByDesc(RxRegistrationPlanSetting::getPlanStatus)
                .orderByDesc(RxRegistrationPlanSetting::getCreateTime);

        Page<RxRegistrationPlanSetting> page = new Page<>(pageNum, pageSize);
        rxRegistrationPlanSettingMapper.selectPage(page, queryWrapper);
        List<RxRegistrationPlanSettingResp> list = page.getRecords()
                .stream()
                .map(plan -> {
                    RxRegistrationPlanSettingResp settingResp = new RxRegistrationPlanSettingResp();
                    BeanUtils.copyProperties(plan, settingResp);

                    SmsUser user = smsUserMapper.selectById(plan.getCreateUser());
                    if (user != null) {
                        SmsSearchUserResp userInfo = new SmsSearchUserResp();
                        BeanUtils.copyProperties(user, userInfo);
                        settingResp.setUserInfo(userInfo);
                    }
                    return settingResp;
                })
                .collect(Collectors.toList());
        int total = (int) page.getTotal();
        return CommonResult.success(list, total);
    }

    @Override
    @Transactional
    public ResponseResult addAndUpdateRxRegistrationPlanDetailSetting(RxRegistrationPlanDetailSettingReq appSettingReq) {
        if (isNullOrEmpty(appSettingReq.getPlanId(), appSettingReq.getAppType(), appSettingReq.getBgTime(),
                appSettingReq.getEndTime(),appSettingReq.getSuccessPromptStatement())) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }

        if (appSettingReq.getAppType() != APP_TYPE_ADVANCE
                && appSettingReq.getAppType() != APP_TYPE_CONFIRM
                && appSettingReq.getAppType() != APP_TYPE_WELCOME) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }

        //时间校验 开始时间小于结束时间
        if (appSettingReq.getBgTime().getTime() > appSettingReq.getEndTime().getTime()) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }

        saveAndUpdateChargeCategory(appSettingReq);
        saveAndUpdateCustomColumn(appSettingReq);
        saveAndUpdateAppSetting(appSettingReq);
        return CommonResult.success();
    }

    @Override
    public ResponseResult getRxRegistrationPlanDetailSetting(Integer appType, String planId) {
        if (appType != APP_TYPE_ADVANCE && appType != APP_TYPE_CONFIRM && appType != APP_TYPE_WELCOME) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }

        RxRegistrationPlanSetting planSetting = rxRegistrationPlanSettingMapper.selectById(planId);
        if (planSetting == null) {
            return CommonResult.failed(CommonCodeEnum.ENROLLMENT_MANAGEMENT_TASK_NOT_EXIST);
        }

        RxRegistrationPlanDetailSettingResp detailSettingResp = new RxRegistrationPlanDetailSettingResp();
        //封装应用配置
        RxRegistrationPlanAppSetting appSetting = rxRegistrationPlanAppSettingMapper.selectOne(new LambdaQueryWrapper<RxRegistrationPlanAppSetting>()
                .eq(RxRegistrationPlanAppSetting::getPlanId, planId)
                .eq(RxRegistrationPlanAppSetting::getAppType, appType));
        if (appSetting != null) {
            BeanUtils.copyProperties(appSetting, detailSettingResp);
        }

        //封装缴费项配置
        List<RxRegistrationChargeCategoryResp> catCategoryRespList = rxRegistrationPlanChargeCategorySettingMapper.selectList(new LambdaQueryWrapper<RxRegistrationPlanChargeCategorySetting>()
                        .eq(RxRegistrationPlanChargeCategorySetting::getPlanId, planId)
                        .eq(RxRegistrationPlanChargeCategorySetting::getAppType, appType))
                .stream()
                .map(chargeCategorySetting -> {
                    RxRegistrationChargeCategoryResp chargeCategoryResp = new RxRegistrationChargeCategoryResp();
                    BeanUtils.copyProperties(chargeCategorySetting, chargeCategoryResp);
                    chargeCategoryResp.setId(chargeCategorySetting.getChargeCategoryId());

                    if (chargeCategorySetting.getChargeCategoryType() == CHARGE_CATEGORY_TYPE_MAJOR) {
                        List<RxRegistrationChargeCategoryDetailJsonResp> childrenList = JSONObject.parseArray(chargeCategorySetting.getChargeCategoryChildren(), RxRegistrationChargeCategoryDetailJsonResp.class);
                        if (childrenList != null) {
                            chargeCategoryResp.setChildrenList(childrenList);
                        }
                    }
                    return chargeCategoryResp;
                })
                .collect(Collectors.toList());
        detailSettingResp.setChargeCategoryList(catCategoryRespList);
        //封装自定义字段配置
        List<RxRegistrationCustomColumnResp> customColumnList = rxRegistrationCustomColumnMapper.selectList(new LambdaQueryWrapper<RxRegistrationCustomColumn>()
                        .eq(RxRegistrationCustomColumn::getPlanId, planId)
                        .eq(RxRegistrationCustomColumn::getAppType, appType))
                .stream()
                .map(customColumnSetting -> {
                    RxRegistrationCustomColumnResp customColumnResp = new RxRegistrationCustomColumnResp();
                    BeanUtils.copyProperties(customColumnSetting, customColumnResp);

                    return customColumnResp;
                })
                .collect(Collectors.toList());
        detailSettingResp.setCustomColumnList(customColumnList);
        return CommonResult.success(detailSettingResp);
    }

    @Override
    public ResponseResult getSuccessStatement(String idCard,Integer appType) {
        if (isNullOrEmpty(idCard)) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }
        // 判断招生计划是否开启
        List<RxRegistrationPlanSetting> planSettingList = rxRegistrationPlanSettingMapper.selectList(new LambdaQueryWrapper<RxRegistrationPlanSetting>()
                .eq(RxRegistrationPlanSetting::getPlanStatus, PLAN_STATUS_ENABLE));
        if (planSettingList == null || planSettingList.size() == 0) {
            return CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_CONFIRM_NOT_PLAN);
        }
        RxRegistrationPlanSetting planSetting = planSettingList.get(0);
        //查学生信息
        List<RxRegistrationAdvanceStudentInfo> studentInfoList = rxRegistrationAdvanceStudentInfoMapper.selectList(new LambdaQueryWrapper<RxRegistrationAdvanceStudentInfo>()
                .eq(RxRegistrationAdvanceStudentInfo::getPlanId, planSetting.getId())
                .eq(RxRegistrationAdvanceStudentInfo::getIdCard, idCard));
        if (studentInfoList == null || studentInfoList.size() == 0) {
            return CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_ADVANCE_STUDENT_NOT_EXIT);
        }
        List<RxRegistrationPlanAppSetting> planAppSettingList = rxRegistrationPlanAppSettingMapper.selectList(new LambdaQueryWrapper<RxRegistrationPlanAppSetting>()
                .eq(RxRegistrationPlanAppSetting::getAppType, appType)
                .eq(RxRegistrationPlanAppSetting::getPlanId, planSetting.getId()));
        if (planAppSettingList == null || planAppSettingList.size() == 0) {
            return CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_CONFIRM_NOT_PLAN);
        }
        RxRegistrationSuccessStatementResp successStatementResp = new RxRegistrationSuccessStatementResp();
        successStatementResp.setName(studentInfoList.get(0).getName());
        successStatementResp.setSuccessPromptStatement(planAppSettingList.get(0).getSuccessPromptStatement());
        successStatementResp.setAppType(planAppSettingList.get(0).getAppType());

        return CommonResult.success(successStatementResp);
    }

    @Override
    public ResponseResult checkRxRegistrationChargeCategory(String chargeCategoryId, String planId) {
        List<RxRegistrationPlanChargeCategorySetting> list = rxRegistrationPlanChargeCategorySettingMapper.selectList(new LambdaQueryWrapper<RxRegistrationPlanChargeCategorySetting>()
                .eq(RxRegistrationPlanChargeCategorySetting::getChargeCategoryId, chargeCategoryId)
                .eq(RxRegistrationPlanChargeCategorySetting::getPlanId, planId));
        if (list != null && list.size() > 0){
            return CommonResult.success(true);
        }
        return CommonResult.success(false);
    }

    /**
     * @description 保存收费项中间表 需求：预报名和确认报名阶段不能设置专业收费项
     * @create 2024/5/13
     * @author dxn
     */
    private void saveChargeCategory(RxRegistrationPlanDetailSettingReq appSettingReq) {
        if (appSettingReq.getChargeCategoryIdList() == null || appSettingReq.getChargeCategoryIdList().size() < 1) {
            return;
        }
        int dormitoryCount = 0;
        for (String chargeCategoryId : appSettingReq.getChargeCategoryIdList()) {
            RxRegistrationChargeCategory chargeCategory = rxRegistrationChargeCategoryMapper.selectById(chargeCategoryId);
            if (chargeCategory == null) {
                ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.ADVANCE_REGISTRATION_PAYMENT_ITEM_NOT_EXIST));
            }

            //非迎新阶段缴费项不能设置专业收费项
            if (appSettingReq.getAppType() != APP_TYPE_WELCOME) {
                if (chargeCategory.getChargeCategoryType() == CHARGE_CATEGORY_TYPE_MAJOR) {
                    ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.ENROLLMENT_MANAGEMENT_CHARGE_CATEGORY_ERROR));
                }
            } else { //迎新缴费阶段  宿舍收费项不能设置多个，有且只有一个
                if (dormitoryCount > 1) {
                    ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_PLAN_CHARGE_CATEGORY_DORMITORY_REPEAT));
                }
                if (chargeCategory.getChargeCategoryType() == CHARGE_CATEGORY_TYPE_DORMITORY) {
                    dormitoryCount++;
                }
            }

            RxRegistrationPlanChargeCategorySetting addSetting = new RxRegistrationPlanChargeCategorySetting();
            addSetting.setPlanId(appSettingReq.getPlanId());
            addSetting.setChargeCategoryId(chargeCategory.getId());
            addSetting.setChargeCategoryName(chargeCategory.getChargeCategoryName());
            addSetting.setChargeCategoryPrice(chargeCategory.getChargeCategoryPrice());
            addSetting.setChargeCategoryType(chargeCategory.getChargeCategoryType());
            addSetting.setAppType(appSettingReq.getAppType());
            addSetting.setIsRequired(chargeCategory.getIsRequired());

            if (chargeCategory.getChargeCategoryType() != CHARGE_CATEGORY_TYPE_NORMAL) {
                List<RxRegistrationChargeCategoryDetail> detailList = rxRegistrationChargeCategoryDetailMapper.selectList(new LambdaQueryWrapper<RxRegistrationChargeCategoryDetail>()
                        .eq(RxRegistrationChargeCategoryDetail::getParentId, chargeCategory.getId()));
                if (detailList != null && !detailList.isEmpty()) {
                    List<RxRegistrationChargeCategoryDetailJsonResp> list = detailList.stream()
                            .map(detail -> {
                                RxRegistrationChargeCategoryDetailJsonResp resp = new RxRegistrationChargeCategoryDetailJsonResp();
                                BeanUtils.copyProperties(detail, resp);
                                resp.setChargeCategoryId(detail.getId());
                                return resp;
                            })
                            .collect(Collectors.toList());
                    addSetting.setChargeCategoryChildren(JSON.toJSONString(list));
                }
            }
            rxRegistrationPlanChargeCategorySettingMapper.insert(addSetting);
        }
    }

    private void saveAndUpdateChargeCategory(RxRegistrationPlanDetailSettingReq appSettingReq) {
        //删除保存收费项中间表
        rxRegistrationPlanChargeCategorySettingMapper.delete(new LambdaQueryWrapper<RxRegistrationPlanChargeCategorySetting>()
                .eq(RxRegistrationPlanChargeCategorySetting::getPlanId, appSettingReq.getPlanId())
                .eq(RxRegistrationPlanChargeCategorySetting::getAppType, appSettingReq.getAppType()));
        saveChargeCategory(appSettingReq);
    }

    /**
     * @description 保存自定义字段
     * @create 2024/5/13
     * @author dxn
     */
    private void saveCustomColumn(RxRegistrationPlanDetailSettingReq appSettingReq) {
        int sort = 1;
        for (RxRegistrationCustomColumnReq columnReq : appSettingReq.getCustomColumnIdList()) {
            if (isNullOrEmpty(columnReq.getColumnName(), columnReq.getIsRequired())) {
                ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.ENROLLMENT_MANAGEMENT_CUSTOM_COLUMN_PARAM_ERROR));
            }

            //已存在字段 更新信息
            if (!isNullOrEmpty(columnReq.getId())) {
                RxRegistrationCustomColumn updateSetting = new RxRegistrationCustomColumn();
                updateSetting.setId(columnReq.getId());
                updateSetting.setColumnName(columnReq.getColumnName());
                updateSetting.setIsRequired(columnReq.getIsRequired());
                updateSetting.setColumnSort(sort++);
                rxRegistrationCustomColumnMapper.updateById(updateSetting);
            } else {//不存在字段 添加信息
                RxRegistrationCustomColumn addSetting = new RxRegistrationCustomColumn();
                addSetting.setPlanId(appSettingReq.getPlanId());
                addSetting.setAppType(appSettingReq.getAppType());
                addSetting.setColumnName(columnReq.getColumnName());
                addSetting.setIsRequired(columnReq.getIsRequired());
                addSetting.setColumnSort(sort++);
                rxRegistrationCustomColumnMapper.insert(addSetting);
            }

        }
    }

    private void saveAndUpdateCustomColumn(RxRegistrationPlanDetailSettingReq appSettingReq) {
        //删除自定义字段
        if (!isNullOrEmpty(appSettingReq.getCustomColumnIdDeleteList()) && !appSettingReq.getCustomColumnIdDeleteList().isEmpty()) {
            rxRegistrationCustomColumnMapper.delete(new LambdaQueryWrapper<RxRegistrationCustomColumn>()
                    .in(RxRegistrationCustomColumn::getId, appSettingReq.getCustomColumnIdDeleteList()));
        }
        saveCustomColumn(appSettingReq);
    }


    /**
     * @description 保存应用设置
     * @create 2024/5/13
     * @author dxn
     */
    private void saveAppSetting(RxRegistrationPlanDetailSettingReq appSettingReq) {
        RxRegistrationPlanAppSetting addSetting = new RxRegistrationPlanAppSetting();
        addSetting.setAppType(appSettingReq.getAppType());
        addSetting.setPlanId(appSettingReq.getPlanId());
        addSetting.setBgTime(appSettingReq.getBgTime());
        addSetting.setEndTime(appSettingReq.getEndTime());
        addSetting.setSuccessPromptStatement(appSettingReq.getSuccessPromptStatement());
        rxRegistrationPlanAppSettingMapper.insert(addSetting);
    }

    private void saveAndUpdateAppSetting(RxRegistrationPlanDetailSettingReq appSettingReq) {
        //删除应用设置
        rxRegistrationPlanAppSettingMapper.delete(new LambdaQueryWrapper<RxRegistrationPlanAppSetting>()
                .eq(RxRegistrationPlanAppSetting::getPlanId, appSettingReq.getPlanId())
                .eq(RxRegistrationPlanAppSetting::getAppType, appSettingReq.getAppType()));
        saveAppSetting(appSettingReq);
    }


}
